package com.jason.user.model;

import com.jason.user.dao.entity.User;
import com.jason.user.dao.entity.UserSign;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.*;


public class UserModel {

    private Integer id;

    @Length(min = 2, max = 10)
    @NotBlank
    private String name;

    @DecimalMin("0")
    @DecimalMax("150")
    private Integer age;

    @Email
    private String email;

    @NotBlank
    private String telephone;

    private Byte gender;

    private String regType = "byPhone";

    private String regAccount;

    @NotBlank
    @Length(min = 2, max = 10)
    private String password;


    public static UserModel  convertFromUserEntity(User user, UserSign userSign) {
        if (user == null){
            return null;
        }
        UserModel userModel = new UserModel();
        BeanUtils.copyProperties(user, userModel);
        if (userSign != null){
            userModel.setPassword(userSign.getPassword());
        }
        return userModel;
    }

    public User convertToUser() {
        User user = new User();
        BeanUtils.copyProperties( this, user);
        return user;
    }
    public UserSign convertToUserSign() {
        UserSign userSign = new UserSign();
        userSign.setPassword(this.password);
        userSign.setUserId(this.id);
        return userSign;
    }





    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public Byte getGender() {
        return gender;
    }

    public void setGender(Byte gender) {
        this.gender = gender;
    }

    public String getRegisterType() {
        return regType;
    }

    public void setRegisterType(String regType) {
        this.regType = regType;
    }

    public String getRegisterAccount() {
        return regAccount;
    }

    public void setRegisterAccount(String regAccount) {
        this.regAccount = regAccount;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
